package com.transaction.simulate.controller;

import com.transaction.common.base.BaseController;
import com.transaction.common.util.ParamsUtil;
import com.transaction.simulate.model.dto.Fund;
import com.transaction.simulate.model.vo.FundVo;
import com.transaction.simulate.service.FundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/fund")
public class FundController extends BaseController {

    @Autowired
    private FundService fundService;

    //获得产品信息列表
    @GetMapping("/getFundList")
    public Object getFundList(HttpServletRequest request){
        Fund fund = ParamsUtil.getBeanParam(new Fund(),request);
        List<FundVo> list = fundService.getFundList(fund.getChannelCode(),fund.getFundCode());
        return retResultVo(list);
    }

    //产品信息查看数据
    @GetMapping("/getViewFundData")
    public Object getViewFundData(HttpServletRequest request){
        Map<String,Object> map = ParamsUtil.getParams(request);
        Map<String,Object> data = fundService.getViewFundData(map);
        return retResultVo(data);
    }

    //查看单个产品数据
    @GetMapping("/getFundVo")
    public Object getFundVo(HttpServletRequest request){
        Map<String,Object> map = ParamsUtil.getParams(request);
        FundVo fundVo = fundService.getFundVo(map);
        return retResultVo(fundVo);
    }

    @PostMapping("/deleteFund")
    public Object deleteFund(@RequestBody Fund fund){
        fundService.deleteFund(fund);
        return retResultVo();
    }

    @PostMapping("/addFund")
    public Object addFund(@RequestBody Fund fund){
        fundService.addFund(fund);
        return retResultVo();
    }

}
